package com.zjw.zy.heart.utils;

import com.zjw.zy.heart.constant.FileConstant;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class CrashUtils {
    public static void save(String time, String crash) {
        File root = new File(FileConstant.CRASH_PATH);
        if (!root.exists()) {
            boolean mkdirs = root.mkdirs();
            if (!mkdirs) {
                return;
            }
        }
        File file = new File(FileConstant.CRASH_PATH + "/" + time + ".txt");
        if (!file.exists()) {
            try {
                boolean newFile = file.createNewFile();
                if (!newFile) {
                    return;
                }

                FileOutputStream os = new FileOutputStream(file);
                os.write(crash.getBytes(StandardCharsets.UTF_8));

                os.close();

            } catch (IOException ignore) {

            }
        }
    }
}
